package common.controls.utils
{
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.utils.setTimeout;
	
	import kernel.application.ApplicationDisplay;
	
	/**  
	 * 
	 * @author carrey
	 * */ 
	public class SpriteUtils
	{
		
		public static function getSprite( w:Number=10, h:Number=10, color:Number=0xffffff ):Sprite
		{
			var s:Sprite = new Sprite();
			s.graphics.beginFill( color );
			s.graphics.drawRoundRect( 0, 0, w, h, 0, 0 );
			s.graphics.endFill();
			
			return s;
		}
		
		private static var _arrFun:Array = new Array(); 
		private static var _isEnterFrame:Boolean = false;
		public static function callLater( fun:Function, isUnique:Boolean=false ):void
		{
			if( isUnique )
			{
				for( var i:int=0; i<_arrFun.length; i++ )
				{
					if( _arrFun[i]==fun ) return;
				}
			}
			_arrFun.push( fun );
			
			if( !_isEnterFrame )
			{
				_isEnterFrame = true;
				ApplicationDisplay.stage.addEventListener( Event.ENTER_FRAME, onEnterFrame, false, 0, true );
			}
		}
		
		private static function onEnterFrame( e:Event ):void
		{
			_isEnterFrame = false;
			ApplicationDisplay.stage.removeEventListener( Event.ENTER_FRAME, onEnterFrame );
			while( _arrFun.length > 0 )
			{
				_arrFun.pop()();
			}
		}
	}
}